<?php
    /**
     * Created by PhpStorm.
     * User: timeteam
     * Date: 18-11-5
     * Time: 下午5:08
     */

    namespace app\member\logic;


    /**
     * 自定义的模板引擎
     * 通过该类对象加载模板文件并解析，将解析后的结果输出
     * Class MessageTpl
     * @package app\member\logic
     */
    class MessageTpl
    {
        /**
         * @param $replace_content 模版的变量
         * @param $tpl_content 模板内容
         * @return null|string|string[]
         */
        static public function TempReplace($replace_content, $tpl_content)
        {

            //计算短信模版中有多少需要替换的内容变量
            $replace = substr_count($tpl_content, '#');
            //计算几个变量
            $number = intval(floor($replace / 2));
            //重复，去除，分割数组(由内到外)
            $pattern = explode(',', rtrim(str_repeat("/#\w+#/,", $number), ','));
            //正则匹配
            $tpl_content = preg_replace($pattern, $replace_content, $tpl_content, 1);
            return $tpl_content;
        }
    }